package com.lt.lumentracks.task;

import com.lt.lumentracks.service.IPostService;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
@Slf4j
public class HotPostRefreshTask {
    
    @Autowired
    private IPostService iPostService;

    // 设置任务停止状态
    @Getter
    @Setter
    private volatile boolean taskStopped = false; // 任务停止标志


    // 刷新热门帖子榜（移除@Scheduled注解，改为手动调用）
    public void refreshHotPosts() {
        try {
            log.info("开始刷新热门帖子榜");
            String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); // 获取当前日期

            // 刷新今日热门
            iPostService.refreshDailyHotPosts(today);

            log.info("热门帖子榜刷新完成");
        } catch (Exception e) {
            log.error("刷新热门帖子榜失败", e);
        }
    }


}